import { ResponseCode } from './enums';
export class Response {
  constructor(
    private code: ResponseCode,
    private msg?: string,
    private data?: any,
  ) {}

  setData(data: any) {
    this.data = data;
    return this;
  }

  static build(code: number, msg?: string, data?: any): Response {
    const response = new Response(code, msg, data);
    return response;
  }

  static success(): Response {
    return Response.build(ResponseCode.ok, 'ok');
  }

  static successMsg(msg: string): Response {
    return Response.build(ResponseCode.ok, msg);
  }

  static fail(): Response {
    return Response.build(ResponseCode.fail, 'fail');
  }
  static failMsg(msg: string): Response {
    return Response.build(ResponseCode.fail, msg);
  }
}
